/*
 * Datafile.h
 *
 *  Created on: Apr 19, 2011
 *      Author: Erwin,
 */

#ifndef DATAFILE_H_
#define DATAFILE_H_

#include "Inode.h"
#include "FS.h"

class Datafile {
protected:
	bool bread;
	bool bwrite;
	bool bcreate;
	bool bexclusive;
	bool btruncate;
	Inode* inode; //link to inode of the file, so we can find the contents of the file
	int opened; //how many times the file is currently used (might not be needed)
	int permissions; //can the file be written/read
	FS* fs; //needed to read file data
	int iopos; //track read/write position (in bytes)
public:
	Datafile(Inode*, int = 0);
	int getInodeNr(){ return inode->getInodeNr(); };
	ssize_t read(void*, size_t); //read [count] number of bytes to buffer, returns amount of bytes actually read
	ssize_t write(void* buffer, size_t count);
	int getiopos(){ return iopos; };
	off_t lseek(off_t, int);
	Inode* getInode(){ return inode; };
	virtual ~Datafile();
};

#endif /* DATAFILE_H_ */
